import jwt
from django.conf import settings



def generate_jwt_token(payload, secret_key=settings.SECRET_KEY):
    """生成jwt"""
    return jwt.encode(payload, secret_key, algorithm='HS256')


def verify_token(token, secret_key=settings.SECRET_KEY):
    """验证jwt"""
    try:     
        return jwt.decode(token.split(' ')[1], secret_key, algorithms=['HS256']),0
    except jwt.ExpiredSignatureError:
        return {'message':"token已过期","code": 401},1

    except jwt.InvalidTokenError:
        return {'message':"token无效","code": 401},1
   
